<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");
require_once("./_inc/layoutFunction.php");

$errMsg = "";
$layout = sxREQUEST("layout");
$band = sxREQUEST("band");

if(sxREQ("reqtype") == "save"){
	$errMsg .= layoutBandMod();
}
if(sxREQ("reqtype") == ""){
	$sSQL = "SELECT * FROM layout_band " .
				" WHERE layout='$layout' " .
				" AND band='$band' ";
	$objSDAO->query($sSQL,"sel");
	if(!$row = $objSDAO->fetch("sel")){
		$errMsg .= _t("no band '%s'",sxREQ('layout')."/".sxREQ('band'))."<br>";
		$url = $_SESSION[USEROBJ]->getHistory(0, true)."&msg=".urlencode($errMsg);
		serverRedir($url);
	}			
	sxRDef('band', $row['band']);
	sxRDef('new_band', $row['band']);
	sxRDef('description', $row['description']);
	sxRDef('display_only', $row['display_only']);
	sxRDef('flags', $row['flags']);
	sxRDef('note', $row['note']);
	sxRDef('upgrade_status', $row['upgrade_status']);
}

$aOpz = array("kMenu"=>'pro.lay', "isReloadable"=>$isReloadable);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
function objFrmSubm(rt){
	document.objFrm.reqtype.value = rt;
	document.objFrm.submit();
}
</script>
  
<?php
echo(bodyHTML($aOpz));

echo getLOHeader($layout);

$aCmd = array("insMD"=>array("pag"=>"javascript:objFrmSubm('save')",
										"title"=>_t("save"),
										"text"=>_t("save")
										),
					"back"=>array()
					);
$sCmd = (commandsHTML($aCmd));	
echo $sCmd;

echo getHtmlForm('objFrm');
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('reqtype','...');
echo getHtmlHidden('layout');
echo getHtmlHidden('band');

echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" width=\"20%\" colspan='2'>Layout Band</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Band*</td>" .
			"<td class=\"text01\">".
			getHtmlText('new_band',4)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Description</td>" .
			"<td class=\"text01\">".getHtmlText('description',80)."</td>" .
		"</tr>\n");
$aValDO = array('Y'=>'Yes','N'=>'No');
echo("<tr>" .
			"<td class=\"labl01\">Display only</td>" .
			"<td class=\"text01\">".getHtmlRadio('display_only',$aValDO).
		"</td>\n</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Flags</td>" .
			"<td class=\"text01\">".getHtmlText('flags',80)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Note</td>" .
			"<td class=\"text01\">".getHtmlTextArea('note',80,3)."</td>" .
		"</tr>\n");
echo("</table>");
echo("</form>");

echo $sCmd;
echo(footerHTML());
exit();

function layoutBandMod(){
 	global $objSDAO;
	$errMsg = "";
	if(strlen(sxREQUEST("new_band")) == 0 or strlen(sxREQUEST("new_band")) > 4 
	or ereg("[^0-9]",sxREQUEST("new_band")))
		$errMsg .= "band code not numeric<br>";
	if($errMsg != ""){return $errMsg;}	
	$_REQUEST['new_band'] = str_pad($_REQUEST['new_band'],4,'0',STR_PAD_LEFT);
	if (sxREQ('new_band') != sxREQ('band')) {
		//existence
		$sSQL = "SELECT count(*) as num FROM layout_band " .
				" WHERE layout='".$_REQUEST["layout"]."' " .
				" AND band='".$_REQUEST["new_band"]."'";
		$objSDAO->query($sSQL,"test");
		$row = $objSDAO->fetch("test");
		if($row["num"] != 0)
			$errMsg .= "band existing<br>";
	}
	if($errMsg != ""){return $errMsg;}	
	$sSQL = "UPDATE layout_band SET band = '".sxRAS('new_band')."'" .
			", flags = '".sxRAS("flags")."', " .
			", display_only = '".sxRAS("display_only")."', " .
			", description = '".sxRAS("description")."', " .
			", note = '".sxRAS("note")."'" .
			" WHERE layout = '".sxRAS("layout")."' " .
			" AND band = '".sxRAS("band")."' ";	
	$objSDAO->exec($sSQL);
	$url = $_SESSION[USEROBJ]->getHistory(0, true);
	serverRedir($url);
	return 'abnormal end';
}
